/*
	This file is part of "Ants on the web".

    "Ants on the web" is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Ants on the web" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Ants on the web".  If not, see <http://www.gnu.org/licenses/>.
*/

package org.utc.ia04.antsontheweb.gui.surveillance;

import org.utc.ia04.antsontheweb.utilities.Requete;
import org.utc.ia04.antsontheweb.utilities.RequeteException;

import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;

public class AgentInterfaceSurveillanceBhv extends CyclicBehaviour
{
	//serialVersionUID
	private static final long serialVersionUID = -3413613384256282488L;

	public void action()
	{
		ACLMessage message = myAgent.receive();
		if(message == null)
			block();
		else
		{
			try
			{
				Requete r = Requete.deserialize_withException(message.getContent(), myAgent, message);
				if(r.getType() == Requete.INFORM_BIG_BROTHER)
				{
					try
					{
						((AgentInterfaceSurveillance)myAgent).sendEvent(Integer.valueOf(r.getContent()));
					}
					catch(Exception e)
					{
						((AgentInterfaceSurveillance)myAgent).sendEvent(r.getContent());
					}
				}
			}
			catch (RequeteException e) { }
		}
	}
}
